import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:myflutterproject/xiangqingpage.dart';

import 'everyones.dart';

class CupertinoTabViewDemo extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => CupertinoTabViewState();
}

class CupertinoTabViewState extends State<CupertinoTabViewDemo> {
  @override
  Widget build(BuildContext context) {
    return CupertinoTabScaffold(
      //选项卡
      tabBar: _cupertinotabbar(),
      //控制器，控制选中选项卡
      controller: CupertinoTabController(initialIndex: 0),
      backgroundColor: Colors.yellow,
      tabBuilder: (context, index) {
        return CupertinoTabView(
          //路由设置
          routes: {
            '/flutterDemo/index': (contxt) => EveryOnesDemo('劳务', '劳务内容'),
            '/flutterDemo/mine': (contxt) => EveryOnesDemo('我的', '我的内容'),
          },
          //构建函数
          builder: (context) {
            switch (index) {
              case 0:
                return EveryOnesDemo('劳务', '劳务内容');
              case 1:
                return EveryOnesDemo('我的', '我的内容');
              default:
                return EveryOnesDemo('劳务', '劳务内容');
            }
          },
        );
      },
    );
  }

  CupertinoTabBar _cupertinotabbar() {
    return CupertinoTabBar(
      onTap: (index) {
        print('index');
      },
      //默认选中位置
      currentIndex: 0,
      //tabbar 背景色
      backgroundColor: Colors.lightBlueAccent,
      //图标高亮颜色
      activeColor: Colors.blue,
      //图标未选中颜色
      inactiveColor: Colors.grey,
      //图标大小
      iconSize: 30,
      //边框
      border: Border(top: BorderSide(width: 3, color: Colors.white)),
      items: [
        _bottomNavigationBarItem(Image.asset('images/index_02.png'),
            Image.asset('images/index_01.png'), '劳务'),
        _bottomNavigationBarItem(Image.asset('images/mine_02.png'),
            Image.asset('images/mine_01.png'), '我的'),

      ],
    );
  }

  BottomNavigationBarItem _bottomNavigationBarItem(
      Image activityIcon, Image unactivityIcon, String title) {
    return BottomNavigationBarItem(
        icon: unactivityIcon,
        activeIcon: activityIcon,
        label: title,
        backgroundColor: Colors.yellow);
  }
}
